package com.logindemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.logindemo.domain.Account;
import com.logindemo.domain.LoginAccount;
import com.logindemo.repository.AccountRepository;
import com.logindemo.service.AccountService;
import com.logindemo.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountRepository accountRepository;
    @Autowired
    private AuthenticationManager authenticationManager;
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 登录
     * 1.交由UsernamePasswordAuthenticationToken认证用户密码是否正确
     * 2.认证成功后生成jwt令牌，令牌内容体为用户id
     * 3.认证成功后将用户信息存入redis
     * 4.最后将token返回给前端
     * @param account
     * @return
     */
    @Override
    public HashMap<String, String> login(Account account) {
       throw new RuntimeException("待完成");
    }

    /**
     * 从springSecurity上下文获取用户信息，从而获取到用户id去删除redis里面用户信息
     * @return
     */
    @Override
    public Boolean logout() {
        throw new RuntimeException("待完成");
    }

    /**
     * 密码加密保存用户信息
     * @param account
     * @return
     */
    @Override
    public Account register(Account account) {
        throw new RuntimeException("待完成");
    }
}
